#include <pthread.h>
#include <functional>
#include <tuple>
class Thread
{
    
    using _F=std::function<void()>;
    
    static void* threadroutine(void* arg)
    {
        reinterpret_cast<Thread*>(arg)->func();
        return nullptr;
    }
    public:
    template<typename F,typename... Args>
    Thread(F&& f,Args&&... args)
    {
        //创建线程并启动
        func=std::bind(std::forward<F>(f), std::forward<Args>(args)...);
        pthread_create(&thread,nullptr,threadroutine,this);
    }
    //获取线程id
    unsigned long get_id()
    {
        return thread;
    }
    //线程等待
    void join()
    {
        pthread_join(thread,nullptr);//暂时不关心返回值
    }
    //线程分离
    void detach()
    {
        pthread_detach(thread);
    }
    private:
    Thread(const Thread&) = delete;
    pthread_t thread;
    _F func;
};